import { fileURLToPath, URL } from "node:url";
import Components from "unplugin-vue-components/vite";
import { VantResolver } from "unplugin-vue-components/resolvers";
import { defineConfig } from "vite";
import vue from "@vitejs/plugin-vue";

// https://vitejs.dev/config/
export default defineConfig({
  plugins: [
    vue(),
    Components({
      resolvers: [VantResolver()],
    }),
  ],
  base: "./", // 基路径
  mode: "development", // 代码环境  开发和生产    production 生产环境
  server: {
    //开发的服务器配置
    host: "0.0.0.0", // 0.0.0.0
    port: 8000,
    open: true, // 自动打开浏览器
    proxy: {
      // 反向代理
      // maoer 代理对象
      // 前端的请求的是前端的服务地址  http://localhost:8000
      // 真正发送到后端的请求时候  maoer 代理对象  换成  target 目标地址
      "/maoer": {
        target: "https://www.missevan.com/", //代理的地址  代理只能代理域名
        changeOrigin: true,
        rewrite: (path) => path.replace(/^\/maoer/, ""), //这里的/需要转义
      },

      "/bili": {
        target: "https://mall.bilibili.com/", //代理的地址  代理只能代理域名
        changeOrigin: true,
        rewrite: (path) => path.replace(/^\/bili/, ""), //这里的/需要转义
      },
    },
  },
  resolve: {
    alias: {
      "@": fileURLToPath(new URL("./src", import.meta.url)),
    },
  },
});
